<?php
namespace app\index\controller;

use think\Session;
use think\Db;

class Team extends Ubase
{
	public function __construct()
	{
		parent::__construct();
		if (!Session::has('aid')) {
			echo'<script>alert("请登录");window.location.href="/"</script>';
		}
	}

	public function index ()
	{
		$user = [];
        $no_title = db('notice')->order('create_time desc')->where('n_keywords',0)->field('n_title')->limit(3)->select();
        $this->assign('notice',$no_title);
        if (Session::has('aid')) {
            $user = db('ns_user')->where('id',Session::get('aid'))->find();
        }
        $this->assign('user',$user);
        $id = Session::get('aid');
        $puser = Db::table('ns_user')
			->where('id','IN',function($query) use ($id){
		    	$query->table('ns_user')->where('id',$id)->field('pid');
			})
			->find();
		if($puser){
			$puser['username'] = substr_replace($puser['username'], '*', 0, 3);
			$puser['mobile'] = substr_replace($puser['mobile'], '****', 3, 4);
		}
		$this->assign('puser',$puser);
		$groups = db('ns_user_group')->field('id,group_name')->select();
		$group = [];
		foreach ( $groups as $v ) {
			$group[$v['id']] = $v['group_name'];
		}
		$this->assign('group',$group);

		$junior = db('ns_user')->where('pid',$id)->select();
		$this->assign('junior',$junior);
		return $this->fetch();
	}

}